# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Thayne McCombs <astrothayne@gmail.com>

pkgname=dart-sass
pkgver=1.65.1
pkgrel=1
pkgdesc='Sass makes CSS fun again'
arch=('loong64' 'x86_64')
url='http://sass-lang.com/'
license=('MIT')
depends=('glibc')
makedepends=('git' 'dart' 'buf')
options=('!strip')
provides=('sass')
conflicts=('ruby-sass')
_commit='bb244761d301d3ac08adc2177d9982d6e0c0d643'
_sass_commit='8b0296ab876115be26d9e5dab02e47a811487fba' # embedded-protocol-2.1.0
source=(
  "$pkgname::git+https://github.com/sass/dart-sass.git#commit=$_commit"
  "github.com-sass-sass::git+https://github.com/sass/sass.git#commit=$_sass_commit"
)
b2sums=('SKIP'
        'SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags
}

prepare() {
  cd "$pkgname"

  mkdir -p build
  ln -sf "$srcdir/github.com-sass-sass" build/language

  # disable analytics
  dart --disable-analytics

  # download dependencies
  dart pub get
}

build() {
  cd "$pkgname"

  UPDATE_SASS_PROTOCOL=false dart run grinder protobuf
  dart compile exe \
    -Dversion=$pkgver \
    -Dprotocol-version=$(cat build/language/spec/EMBEDDED_PROTOCOL_VERSION) \
    -o sass \
    bin/sass.dart
}

package() {
  cd "$pkgname"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" sass

  # embedded-protocol protobuf file
  install -vDm644 -t "$pkgdir/usr/share/$pkgname" build/language/spec/embedded_sass.proto

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
